import React from 'react';
import store, { StoreContext } from '../store/store';

export class Home extends React.Component<any, any> {
    static contextType = StoreContext;
    constructor(props: any) {
        super(props);
        this.state = {
            currentUser: store.currentUser,
        }
    }
    testF = () => {
        alert(store.currentUser.nickName)
    }
    componentDidMount() {
    }
    render() {
        let currentUser:any = {}
        if (this.context.store && this.context.store.currentUser) {
            currentUser = this.context.store.currentUser;
        }
        let {nickName, score} = currentUser;
        if (this.context.logined) {
            return <div>
                <div className="st-btn" onClick={this.testF}>ok</div>
                {nickName} score: {score}
            </div>
        } else {
            return <div>
                Please login firstly.
            </div>
        }
    }
}